import 'package:banyou_app/app/routes/app_pages.dart';
import 'package:banyou_app/app/util/common_utils.dart';
import 'package:banyou_app/app/util/string_util.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

class MydongtaiController extends GetxController {
  final type = 0.obs;
  final dynamics = [].obs;
  final userMap = {}.obs;
  @override
  void onInit() {
    if (Get.arguments != null && Get.arguments['type'] == null) {
      dynamics.value = Get.arguments['Dynamics'] ?? [];
      userMap.value = Get.arguments;
    } else {
      type.value = 1;
      // List mydongt = box.read('mydongtai') ?? [];
      // if (mydongt.length > 0) {
      //   userMap.value = {
      //     'UserName': phoneNumberStr(box.read('mobile')),
      //     'Distance': '4.9KM',
      //     'UserGender': "男",
      //     'UserAvatar':
      //         'https://aqcdn.olbibo.com.cn/Qa/1aa68c75c4a77c87f97fb686b2f068676.png',
      //   };
      //   dynamics.value = mydongt;
      // }
    }
    super.onInit();
  }

  delteDt(index) {
    // box.write('mydongtai', [
    //   // {
    //   //   "Content": "天空下雨了，可以打伞；心下雨了，该怎么办呢？",
    //   //   "AddTime": "5天前",
    //   //   "PictureUrl":
    //   //       "https://aqcdn.olbibo.com.cn/Qa/19246444d94f081e3549803b928260f56.png",
    //   //   "ViewNum": 278,
    //   //   'isDelete': 1,
    //   // }
    // ]);
    EasyLoading.show();
    Future.delayed(Duration(seconds: 2), () {
      EasyLoading.dismiss();
      dynamics.removeAt(index);
      box.write('mydongtai', dynamics.value);
      EasyLoading.showToast('删除成功');
    });
  }

  addDongTai() {
    Get.toNamed(Routes.ADDDONGTAI)?.then((value) {
      if (value == 1) {}
    });
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {}
}
